#include <iostream>
#include <string>
#include <cstdio>
#include <array>

void checkUpdateWithSystemCurl() {
    std::string command = "curl -s -u your_username:your_password ftp://your_ftp_server.com/path/to/latest_version.txt";
    std::array<char, 256> buffer;
    std::string result;
    FILE* pipe = popen(command.c_str(), "r");

    if (!pipe) {
        std::cerr << "popen() failed!" << std::endl;
        return;
    }

    while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
        result += buffer.data();
    }

    int return_code = pclose(pipe);
    if (return_code == 0) {
        std::cout << "Fetched version info (system curl):\n" << result << std::endl;
    } else {
        std::cerr << "System curl command failed with code: " << return_code << std::endl;
        if (!result.empty() && result.find_first_not_of(" \t\n\v\f\r") != std::string::npos) {
             std::cerr << "Output/Error from command:\n" << result << std::endl;
        }
    }
}